package cn.hd01.service;

import java.io.File;

import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class UploadService {

	@Value("${upload.dir}")
	private String uploadDir;

	public File getFile(String orgName ,String basepath) {
		File headpath = new File(basepath);
//		File headpath = new File(uploadDir);
		if (!headpath.exists()) {
			headpath.mkdirs();
		}

		String filename = UUID.randomUUID().toString() + "." + FilenameUtils.getExtension(orgName);
		return new File(headpath, filename);
	}
	
	public File getServerFile(String name) {
		return new File(new File(uploadDir), name);
	}
}
